package com.jn.rxjava.views;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.jn.rxjava.R;


public class MainActivity extends AppCompatActivity {

    private EditText editTextWeatherUrl, editTextNewsUrl;
    private Button buttonGetWeather, buttonGetNews;
    private TextView textViewResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editTextWeatherUrl = findViewById(R.id.editTextWeatherUrl);
        editTextNewsUrl = findViewById(R.id.editTextNewsUrl);
        buttonGetWeather = findViewById(R.id.buttonGetWeather);
        buttonGetNews = findViewById(R.id.buttonGetNews);
        textViewResult = findViewById(R.id.textViewResult);

        buttonGetWeather.setOnClickListener(v -> {
            String url = editTextWeatherUrl.getText().toString();
            if (url.equals("https://api.oioweb.cn/api/weather/weather")) {
                Intent intent = new Intent(MainActivity.this, WeatherActivity.class);
                startActivity(intent);
            } else {
                Toast.makeText(this, "URL不正确", Toast.LENGTH_SHORT).show();
            }
        });

        buttonGetNews.setOnClickListener(v -> {
            String url = editTextNewsUrl.getText().toString();
            if (url.equals("https://api.oioweb.cn/api/common/today")) {
                Intent intent = new Intent(MainActivity.this, NewsActivity.class);
                startActivity(intent);
            } else {
                Toast.makeText(this, "URL不正确", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
